package a21_ObjectArray;

/**
 * @Author quan
 * @Description 定义数组村塾4个朋友对象。
 * 属性：姓名，年龄，性别，爱好。求出4个朋友的平均年龄，并统计比平均年龄低的人数有几个，并打印全部信息。
 * @Date 2023/2/3 23:37
 */
public class TestFriend {
    public static void main(String[] args) {
        //1、定义一个朋友类的数组，用于存储朋友对象
        Friend[] arr = new Friend[4];
        //2、创建三个实例对象,并调用带参构造方法
        Friend f1 = new Friend("小红红",19,"女","逛街");
        Friend f2 = new Friend("小兰兰",37,"男","吃饭");
        Friend f3 = new Friend("小紫紫",40,"女","打扮");
        Friend f4 = new Friend("小黄黄",19,"男","追剧");
        //3、将对象存储到数组中
        arr[0] = f1;
        arr[1] = f2;
        arr[2] = f3;
        arr[3] = f4;
        //4、遍历数组，求数组中的年龄这个属性，求和再求平均
        int count = 0;
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            Friend f = arr[i];
            sum+=f.getAge();
        }
        //求平均年龄
        double averagePrice = sum/3;
        System.out.println(averagePrice);
        //遍历数组取出年龄与平均值比较
        for (int i = 0; i < arr.length; i++) {
            Friend f  = arr[i];
            if(f.getAge() > averagePrice){
                count++;
                System.out.println(arr[i].getName()+","+arr[i].getAge()+","+arr[i].getGender()+","+arr[i].getHabit());
            }
        }
        System.out.println(count);
    }
}
